import { render, h } from "vue"
import AAlert from '@/components/AAlert.vue'
import { $t } from '@/lang'

export default {
    alert: (message: string, opts: { title?: string, confirmText?: string, cancelText?: string } = {}) => {
        return new Promise<boolean>(resolve => {
            let vNode = h(AAlert, {
                title: opts.title || $t('AAlert.Tips'),
                message: message,
                confirmText: opts.confirmText || $t('AAlert.Confirm'),
                cancelText: opts.cancelText || $t('AAlert.Cancel'),
                onConfirm(result: boolean) {
                    resolve(result)
                    render(null, window.document.body)
                },
            })
            render(vNode, window.document.body)
        })
    }
}